package com.aidex.quartz.task;

import com.aidex.biz.domain.BizZjwzInfo;
import com.aidex.biz.service.AnHuanProjectApiService;
import com.aidex.biz.service.BizZjwzInfoService;
import com.aidex.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {

    @Autowired
    private AnHuanProjectApiService anHuanProjectApiServie;

    @Autowired
    private BizZjwzInfoService bizZjwzInfoService;

    public String ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
        return "sdfsdfsdf";
    }


    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }


    /**
     * 获取安环的信息
     */
    public void taskAnHuanFindInfo() {
        anHuanProjectApiServie.getCompanyPaiMing();
        anHuanProjectApiServie.getZiChanList();
    }

    /**
     * 一年一次
     *
     * @throws ParseException
     */
    public void taskZjWzInfoToYear() throws ParseException {
        BizZjwzInfo bizZjwzInfo = new BizZjwzInfo();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        bizZjwzInfo.setTimes(sdf.parse(sdf.format(new Date())));
        List<BizZjwzInfo> list = bizZjwzInfoService.findList(bizZjwzInfo);
        if (list.isEmpty()) {
            for (int i = 1; i <= 12; i++) {
                bizZjwzInfo = new BizZjwzInfo();
                String month = i < 10 ? "0" + i : i + "";
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                bizZjwzInfo.setFirstCounts(0L);
                bizZjwzInfo.setXianSuoCounts(0L);
                bizZjwzInfo.setLiAnCounts(0L);
                bizZjwzInfo.setTimes(simpleDateFormat.parse(simpleDateFormat.format(new Date()).substring(0, 4) + "-" + month + "-01"));
                bizZjwzInfoService.save(bizZjwzInfo);
            }
        }
    }
}
